package com.lyk.swap;

import java.util.ArrayList;
import java.util.List;

public class YearPrice extends ShowPrice {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1034309252241935318L;
	private int year;

	public YearPrice() {
		super();
	}

	public YearPrice(int year) {
		super();
		this.year = year;
	}

	@Override
	public String getFormatDate() {
		StringBuilder sb = new StringBuilder();
		sb.append(year + 1900);
		return sb.toString();
	}

	public static List<YearPrice> createYearPriceList(List<MonthPrice> mplist) {
		List<YearPrice> yplist = new ArrayList<YearPrice>();
		int y = -1;
		double profit = 0;
		YearPrice yp = null;
		for (MonthPrice mp : mplist) {
			int mpy = mp.getYear();
			if (y != mpy) {
				if (null != yp) {
					yp.setPrice(mp.getPrice());
					yp.setProfit(profit);
					yplist.add(yp);
				}
				y = mpy;
				yp = new YearPrice(y);
				profit = 0;
			}
			profit += mp.getProfit();
		}
		if (null != yp) {
			yp.setPrice(mplist.get(mplist.size() - 1).getPrice());
			yp.setProfit(profit);
			yplist.add(yp);
		}
		return yplist;
	}

}
